﻿using Data;
using Logic;
using Services.Progress;
using Services.StaticData;

namespace Infrastructure.States
{
    internal class LoadProgressState : IState
    {
        private readonly GameStateMachine _stateMachine;
        private readonly IProgressService _progressService;
        private readonly IStaticDataService _staticDataService;

        public LoadProgressState(GameStateMachine stateMachine, IProgressService progressService,
            IStaticDataService staticDataService)
        {
            _stateMachine = stateMachine;
            _progressService = progressService;
            _staticDataService = staticDataService;
        }

        public void Enter()
        {
            InitNewProgress();
            _stateMachine.Enter<LoadMenuState, string>(Constants.Menu);
        }

        public void Exit()
        {

        }

        private void InitNewProgress()
        {
            var gameData = _staticDataService.Game;
            var heroData = _staticDataService.Hero;
            _progressService.Progress = new PlayerProgress
            {
                GameSceneData =
                {
                    FieldSideSize = gameData.FieldSideSize,
                    FloorElementSize = gameData.FloorElementSize,
                    FieldSideSizeIncrement = gameData.FieldSideSizeIncrement,
                    ObstaclesQuantityDivideFactor= gameData.ObstaclesQuantityDivideFactor,
                    CameraSize= gameData.CameraSize,
                    CameraSizeIncrement= gameData.CameraSizeIncrement,
                    LevelGenerationTime= gameData.LevelGenerationTime,
                    CreateAnimationTime= gameData.CreateAnimationTime,
                    ObstacleTargetScale= gameData.ObstacleTargetScale
                },
                HeroState =
                {
                    InitialLives = heroData.InitialLives,
                    MaxGuns = heroData.MaxGuns,
                    CurrentGuns = 1,
                    MaxAmmo = heroData.MaxAmmo,
                    CurrentScore = 0
                }
            };
            _progressService.Progress.HeroState.ResetLives();
            _progressService.Progress.HeroState.ResetAmmo();
        }
    }
}